package com.itheima.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;

public class MapperUtils {
    private static SqlSessionFactory build;
    public static ThreadLocal<SqlSession> tl = new ThreadLocal<>();
    static{
        try {
            build = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("SqlMapConfig.xml"));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static SqlSession getSqlSession(){
        SqlSession sqlSession = build.openSession();
        tl.set(sqlSession);

        return sqlSession;
    }
}
